<script type="text/javascript">
	var form_url = '/weixin/news/add/article' ;
	$(function() {
		if(null != $obj.category_row()) {
			$('#category').html($obj.category_row().category);
		} else {
			$('#category_tr').hide();
		}
		
		$('#fileupload').fileupload({
			url: '/weixin/upload',
			autoUpload: true, acceptFileTypes: /(\.|\/)(gif|jpe?g|png)$/i,
			previewCrop: true, previewMaxWidth: 150, previewMaxHeight: 80,
	    }).on('fileuploadprocessalways', function (e, data) {
	    	var index = data.index, file = data.files[index], node = $('.preview');
	        if (file.preview) {
	            node.html(file.preview);
	        }
	    }).on('fileuploadprogressall', function (e, data) { //上传进度
	        var progress = parseInt(data.loaded / data.total * 100, 10);
	    	$('#progress').html('<img src="/static/images/loading.gif" width="13" height="13">');
	    }).on('fileuploaddone', function (e, data) { //上传完成
	    	$('#progress').html('<span style="color: green;">成功：'+data.files[0].name+'</span>');
	    	$('input[name=picUrl]').val(data.result.data.fullUrl) ;
	    }).on('fileuploadfail', function (e, data) { //上传失败
	    	$('#progress').html('<span style="color: red;">失败：'+data.files[0].name+'</span>');
	    });
		
		if(null != "" && "${id!}" != "") {
			form_url = '/weixin/news/update/article' ;
			$.get('/weixin/news/get/article/${id!}', function(result) {
				try {
					$('#form').form('load', result);
				} catch(e) {
					$.easyui.loaded(); console.error(e) ;
				}
			}, 'JSON').complete(function(){$.easyui.loaded();});
		}		
	});
	
	function submitForm() {
		var checkform = $('#form').form('validate');
		if(checkform) {
			$.easyui.loading();
			$.post(form_url, MM.getData('#form', true), function(result) {
				try {
					if(result.code == 200) {
						$obj.article_reload();$window.window('close');alertify.success(result.message);
					} else {
						$.messager.alert('提示信息', result.message, 'warning') ;
					}
				} catch(e) {
					$.easyui.loaded(); console.error(e) ;
				}
			}, 'JSON').complete(function(){$.easyui.loaded();});
		}
	}
</script>

<div class="easyui-panel form-panel" data-options="border: false, fit: true">
	<form id="form" method="post">
		<input type="hidden" name="id" value="${id!}">
		<input type="hidden" name="categoryId" value="${categoryId!}">
		<table class="table-form">
			<tr id="category_tr">
				<th>所属类别：</th>
				<td id="category"></td>
			</tr>
			<tr>
				<th>菜单状态：</th>
				<td colspan="3">
					<select class="easyui-combobox" name="status" style="width:180px;" data-options="required:true, editable: false, panelHeight:'auto'">
		                <option value="1">正常</option>
		                <option value="0">禁用</option>
		            </select>
				</td>
			</tr>
			<tr>
				<th>图文排序：</th>
				<td><input class="easyui-numberbox" name="orderNum" value="100" style="width:180px" data-options="min:100, max: 9999,required:true,validateOnCreate:false,validateOnBlur:true"></td>
			</tr>
			<tr>
				<th>图文标题：</th>
				<td><input class="easyui-textbox" name="title" style="width:464px" data-options="required:true,validateOnCreate:false,validateOnBlur:true"></td>
			</tr>
			<tr>
				<th>URL地址：</th>
				<td colspan="3"><input class="easyui-textbox" name="url" style="width:464px" data-options="required:true,validateOnCreate:false,validateOnBlur:true"></td>
			</tr>
			<tr>
				<th>图文描述：</th>
				<td colspan="3"><input class="easyui-textbox" name="description" style="width:97%;height:60px" data-options="multiline:true"></td>
			</tr>
			<tr>
				<th>上传图片：</th>
				<td colspan="3" style="position: relative;">
					<span class="btn btn-success fileinput-button">
	                    <span>选择文件</span>
	                    <input id="fileupload" type="file" name="files" multiple>
	                </span>
	                <input type="hidden" name="picUrl">
	                <span id="progress" style="position: absolute; left: 75px; top: 7px;width: 390px;height: 16px;overflow: hidden;"></span>
				</td>
			</tr>
		</table>
	</form>
	<div class="preview" style="margin-top: 5px;"></div>
	
</div>
<div class="submit-toolbar" id="footer"  style="border-bottom: 0;border-left: 0;border-right: 0;">
	<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-ok" onclick="submitForm()" style="width:80px">提交</a>
	<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-cancel" onclick="MM.closeCurrentWindow()" style="width:80px">关闭</a>
</div>

